package com.yc.bdw.Activity;

import android.text.Html;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;

import com.yc.bdw.Adapter.SelectorListAdapter;
import com.yc.bdw.R;
import com.yc.bdw.model.Product;

import org.kymjs.kjframe.KJActivity;
import org.kymjs.kjframe.ui.BindView;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class SelectorActivity extends KJActivity {
    @BindView(id = R.id.selector_back, click = true)
    private ImageView backBtn;
    @BindView(id = R.id.selector_search)
    private SearchView searchContent;
    @BindView(id = R.id.selector_select, click = true)
    private ImageView selectBtn;
    @BindView(id = R.id.selector_price, click = true)
    private ImageView priceBtn;
    @BindView(id = R.id.selector_sales, click = true)
    private TextView salesBtn;
    @BindView(id = R.id.selector_commodities, click = true)
    private ListView commoditiesList;

    private List<Product> products = new ArrayList<Product>();
    private SelectorListAdapter adapter;

    private String content;

    @Override
    public void setRootView() {
        setContentView(R.layout.activity_selector);
    }

    @Override
    public void initData() {
        super.initData();

//        Bundle bundle = this.getIntent().getExtras();
//        content = bundle.getString("content");

        init();

        adapter = new SelectorListAdapter(aty);
        adapter.setList(products);
    }

    private void init() {
        Product item = new Product();
        item.setPrice(BigDecimal.valueOf(11));
        item.setNumber(6);
        item.setName("酒");
        products.add(item);

        Product item2 = new Product();
        item2.setPrice(BigDecimal.valueOf(22));
        item2.setNumber(7);
        item2.setName("酒2");
        products.add(item2);

        Product item3 = new Product();
        item3.setPrice(BigDecimal.valueOf(33));
        item3.setName("酒3");
        item3.setNumber(8);
        products.add(item3);

        Product item4 = new Product();
        item4.setPrice(BigDecimal.valueOf(44));
        item4.setName("酒4");
        item4.setNumber(9);
        products.add(item4);
    }

    @Override
    public void initWidget() {
        super.initWidget();

        // 搜索
        searchContent.setQueryHint(Html.fromHtml("<font color = 'white'>"
                + getResources().getString(R.string.query_hint) + "</font>"));
        searchContent.onActionViewExpanded();
        searchContent.setFocusable(false);
        searchContent.clearFocus();
        searchContent.setIconified(false);
        searchContent.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextChange(String s) {
                return false;
            }

            @Override
            public boolean onQueryTextSubmit(String s) {
                return false;
            }
        });

        commoditiesList = (ListView) findViewById(R.id.selector_commodities);
        commoditiesList.setAdapter(adapter);
        commoditiesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            }
        });
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
            case R.id.selector_back:
                finish();
                break;
            case R.id.selector_price:
                break;
            case R.id.selector_sales:
                break;
            case R.id.selector_select:
                break;
        }
    }
}
